<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ page import="java.util.*"%>
<%@ page import="cn.edu.cqvie.ssm.entity.User"%>
<%@ page import="cn.edu.cqvie.ssm.model.UserModel"%>
<%@ page import="cn.edu.cqvie.ssm.model.impl.UserModelImpl"%>
<%@ page import="java.net.URLEncoder"%>

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>编辑控制器</title>
</head>
<body>
	<%
		request.setCharacterEncoding("UTF-8");
		response.setCharacterEncoding("UTF-8");
		UserModel um = new UserModelImpl();

		String actionView = request.getParameter("action");
		if (actionView.equals("view")) {
			String id = request.getParameter("id");
			User u = um.load(new Integer(id));
			response.sendRedirect("edit.jsp?id=" + u.getId() + "&name=" + URLEncoder.encode(u.getName(),"UTF-8")+ "&password=" + u.getPassword());
		} else if ("submit".equals(actionView)) {
			int id = Integer.valueOf(request.getParameter("id"));
			String name = String.valueOf(request.getParameter("name"));
			String password = String.valueOf(request.getParameter("password"));
			User user = User.builder()
							.id(id)
							.name(name)
							.password(password)
							.build();
			um.update(user);
			response.sendRedirect("list.jsp");
		}
	%>
</body>
</html>